@extends('app')

@section('content')
<ul class="nav nav-tabs">
    <li ><a href="{{ url('/admin/setting/menu')}}">分类列表</a></li>
    <li class="active"><a href="#">添加分类</a></li>
</ul>
<form method="POST" action="{{ url('/admin/setting/menu') }}">
<table class="table table-striped mt20">
    <tr>
        <td>
            <div class="form-group">
                <span class="col-sm-4 col-xs-3 control-label">菜单名称:</span>
                <div class="col-sm-5 col-xs-8">
                    <input type="text" class="form-control" name="name" id="name" value="{{!empty($result)?$result->name:''}}">
                </div>
            </div>
        </td>
    </tr>
    <tr>
        <td>
            @if($blademode == "edit")
            <div class="form-group">
                <span class="col-sm-4 col-xs-3 control-label">菜单分类:</span>
                <div class="col-sm-5 col-xs-8 form-inline">
                    <select name="type" class="form-control" id="type" onchange="getChilds('admin/sitemenu',this.value,'parent')">
                        <option value="0">主菜单</option>
                        @foreach($sitemenu as $tp)
                        <option value="{{ $tp->menu_id }}" @if($tp->menu_id == $pid) selected @endif>{{ $tp->name }}</option>
                        @endforeach
                    </select>
                    <div class="form-group ml30" id="child_1">
                        @if(!empty($secondmenu))
                        <select name="child_1" class="form-control">
                            @foreach($secondmenu as $sdm)
                            <option value="{{$sdm->cat_id}}" @if($upid == $sdm->cat_id) selected @endif >{{$sdm->cat_name}}</option>
                            @endforeach
                        </select>
                        @endif
                    </div>
                </div>
            </div>
            @else
                <div class="form-group">
                    <span class="col-sm-4 col-xs-3 control-label">上级菜单:</span>
                    <div class="col-sm-5 col-xs-8 form-inline">
                        <select name="type" class="form-control" id="type" onchange="getChilds('admin/sitemenu',this.value,'parent')" >
                            <option value="0">主菜单</option>
                            @foreach($sitemenu as $tp)
                            <option value="{{ $tp->menu_id }}">{{ $tp->name }}</option>
                            @endforeach
                        </select>
                        <div class="form-group ml30" id="child_1"></div>
                    </div>
                </div>
                
            @endif
        </td>
    </tr>
    <tr>
        <td>
            <div class="form-group">
                <span class="col-sm-4 col-xs-3 control-label">菜单描述:</span>
                <div class="col-sm-5 col-xs-8">
                    <input type="text" class="form-control" name="description" id="description" value="{{!empty($result)?$result->description:''}}">
                    <div class="help-block" >菜单描述</div>
                </div>
            </div>
        </td>
    </tr>
    <tr>
        <td>
            <div class="form-group">
                <span class="col-sm-4 col-xs-3 control-label">菜单地址:</span>
                <div class="col-sm-5 col-xs-8">
                    <input type="text" class="form-control" name="url" id="url" value="{{!empty($result)?$result->url:''}}">
                </div>
            </div>
        </td>
    </tr>
    <tr>
        <td>
            <div class="form-group">
                <span class="col-sm-4 col-xs-3 control-label">菜单状态:</span>
                <div class="col-sm-5 col-xs-8">
                    <label class="radio-inline">
                      <input type="radio" name="status" value="0" @if(!empty($result) && $result->status == 0)checked @else checked @endif> 开启
                    </label>
                    <label class="radio-inline">
                      <input type="radio" name="status"  value="1"  @if(!empty($result) && $result->status == 1)checked @endif> 关闭
                    </label>
                </div>
            </div>
        </td>
    </tr>
    <tr>
        <td>
            <div class="form-group">
                <span class="col-sm-4 col-xs-3 control-label">菜单排序:</span>
                <div class="col-sm-5 col-xs-8">
                    <input type="number" class="form-control" name="sort" id="sort" value="{{!empty($result)?$result->sort:''}}">
                    <div class="help-block" >越小越靠前</div>
                </div>
            </div>
        </td>
    </tr>
    <tr>
        <td>
            <div class="form-group">
                <span class="col-sm-4 col-xs-3 control-label">菜单权限:</span>
                <div class="col-sm-5 col-xs-8">
                    <select name="permission" class="form-control">
                        @foreach($perms as $perm)
                        <option value="{{$perm->id}}" @if(!empty($result) && $result->permission_id == $perm->id)selected @endif>{{$perm->display_name}}</option>
                        @endforeach
                    </select>
                </div>
            </div>
        </td>
    </tr>
</table>
    
    {!! csrf_field() !!}
    <input type="hidden" name="menu_id" value={{!empty($result)?$result->menu_id:0}}>
    <div class="form-inline mt20">
        <div class="form-group">
          <input type="hidden" name="stauts" value="1">
          <button type="submit" class="btn btn-info">
                    <i class="icon-ok bigger-110"></i>
                    Submit
          </button>
        </div>
        <div class="form-group ml30">
            <button type="reset" class="btn">
                    <i class="icon-undo bigger-110"></i>
                    Reset
                </button>
        </div>
    </div>
</form>

<script type="text/javascript">
<!--
$(function(){
	/***图片上传****/
	$("#uploadimg").uploadify({
	    'formData'     : {
	        'fileField':'upfile',
	        '_token':'{{ csrf_token() }}',
	        'type':'bbs'
	    },
	    "width"           : 120,
	    "height"          : 30,
	    "queueSizeLimit"  :1,
	    "swf"             : "{{ asset('/js/uploadify/uploadify.swf') }}",
	    "fileObjName"     : "upfile",
	    "buttonText"      : "上传图片",
	    "uploader"        : '/admin/upload/newsimage',
	    'removeTimeout'	  : 1,
	    'fileTypeExts'	  : '*.jpg; *.png; *.gif;',
	    'onUploadSuccess':function(file, data, response){
	    	var data = eval('(' + data + ')');
	        if (data.status == 'success') {

	        	var html="<div style='width:90px; height:60px;float:left;'>"
	            			+"<img width='90' height='60' src='"+data.url+"'  /><input type='hidden' name='icon' value='"+data.url+"' />"
	            			+"</div>"
	            $('#imgbox').html(html);
	        }else{
	            alert(data.msg);
	            return false;
	        }

	    }

	});
});
//-->
</script>
@endsection
